package main

import (
	"bufio"
	"bytes"
	"flag"
	"fmt"
	"net"
	"os"
	"sync"
	"time"
)

var wg sync.WaitGroup

func main() {
	var (
		dict   string
		domain string
	)
	o :=0
	flag.StringVar(&dict, "w", "", "-w /usr/share/wordlists/subdomain.txt")
	flag.StringVar(&domain, "d", "", "-d example.com")
	flag.Parse()
	if len(domain) < 3{
		os.Exit(0)
	}
	if len(dict) < 3{
		os.Exit(0)
	}
	start := time.Now()
	open, _ := os.Open(dict) //修改此处更改为你的子域名字典绝对路径
	defer open.Close()
	scanner := bufio.NewScanner(open)
	scanner.Split(bufio.ScanLines)
	var sliceText []string
	for scanner.Scan() {
		sliceText = append(sliceText, scanner.Text())
	}

	for i := 0; i < len(sliceText); i++ {
		wg.Add(1)
		go func(i int) {
			ip, _ := net.LookupIP(sliceText[i] + "." + domain) //  此处为组合。
			if ip != nil {
				fmt.Println(sliceText[i]+"."+domain, ip) //判断返回的IP 是否为空，如不为空则输出。
				o++
			}
			wg.Done()
		}(i)
	}
	wg.Wait()

	fmt.Printf("%s\n",bytes.Repeat([]byte("-") , 50))
	fmt.Printf("Total Found Domain %v 个\n" , o)
	fmt.Println("Use Time: ", time.Since(start))
}
